package com.mianle.userapi.controller;

import com.mianle.userapi.model.Gaode;
import com.mianle.userapi.service.GaodeService;
import com.mianle.userapi.util.JsonResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.nio.file.Paths;
import java.util.List;
import java.util.Map;

/**
 * 登录功能
 * 登录命令空间前缀/demo
 */
@RestController
@RequestMapping("/demo")
@Validated
public class DemoController {

    @Autowired
    private GaodeService gaodeService;

    private final ResourceLoader resourceLoader;

    @Autowired
    public DemoController(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

/*    @GetMapping("/save")
    public void save() {
        gaodeService.save();
    }*/


    @GetMapping("/all")
    public List<Double[]> all() {
       return gaodeService.getAll();
    }


    @GetMapping("/getMarker")
    public List<Gaode> getMarker() {
        return gaodeService.getMarker(null, null);
    }

    @GetMapping("/getSpatialMarker")
    public JsonResponseData getSpatialMarker() {
        return gaodeService.getSpatialMarker(null, null);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{filename:.+}", produces = {"image/png", "image/jpeg", "image/gif"})
    public ResponseEntity<?> getFile(@PathVariable String filename) {
        try {
            return ResponseEntity.ok(resourceLoader.getResource("file:D:/rentHouse/"+filename));
        } catch (Exception e) {
            return ResponseEntity.notFound().build();
        }
    }
}
